home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / telecomm / sticpsrc.lzh / SOURCE.ARC / TCPDUMP.C < prev    next >
C/C++ Source or Header  |  1990-01-26  |  1KB  |  65 lines

  1. #include <stdio.h>
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "netuser.h"
  5. #include "internet.h"
  6. #include "timer.h"
  7. #include "tcp.h"
  8. #include "trace.h"
  9.  
  10. extern FILE *trfp;
  11.  
  12. /* TCP segment header flags */
  13. char *tcpflags[] = {
  14.     "FIN",    /* 0x01 */
  15.     "SYN",    /* 0x02 */
  16.     "RST",    /* 0x04 */
  17.     "PSH",    /* 0x08 */
  18.     "ACK",    /* 0x10 */
  19.     "URG"    /* 0x20 */
  20. };
  21.  
  22. /* Dump a TCP segment header. Assumed to be in network byte order */
  23. void
  24. tcp_dump(bpp,source,dest,check)
  25. struct mbuf **bpp;
  26. int32 source,dest;    /* IP source and dest addresses */
  27. int check;        /* 0 if checksum test is to be bypassed */
  28. {
  29.     int i;
  30.     struct tcp seg;
  31.     struct pseudo_header ph;
  32.     int16 csum;
  33.  
  34.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  35.         return;
  36.  
  37.     /* Verify checksum */
  38.     ph.source = source;
  39.     ph.dest = dest;
  40.     ph.protocol = TCP_PTCL;
  41.     ph.length = len_mbuf(*bpp);
  42.     csum = cksum(&ph,*bpp,ph.length);
  43.  
  44.     ntohtcp(&seg,bpp);
  45.  
  46.     fprintf(trfp,"TCP: %u->%u Seq x%lx",seg.source,seg.dest,seg.seq,seg.ack);
  47.     if(seg.flags & ACK)
  48.         fprintf(trfp," Ack x%lx",seg.ack);
  49.     for(i=0;i<6;i++){
  50.         if(seg.flags & (1 << i)){
  51.             fprintf(trfp," %s",tcpflags[i]);
  52.         }
  53.     }
  54.     fprintf(trfp," Wnd %u",seg.wnd);
  55.     if(seg.flags & URG)
  56.         fprintf(trfp," UP x%x",seg.up);
  57.     /* Print options, if any */
  58.     if(seg.mss != 0)
  59.         fprintf(trfp," MSS %u",seg.mss);
  60.     if(check && csum != 0)
  61.         fprintf(trfp," CHECKSUM ERROR (%u)",csum);
  62.     fprintf(trfp,"\n");
  63. }
  64.  
  65.